#include "responsehandlerthread.h"
#include <string.h>
#include "client.h"
#include "clientwaitpool.h"

ResponseHandlerThread::ResponseHandlerThread()
:m_requestID(0), m_name(""), m_contentType(""), m_contentLength(0), m_data((void*)0)
{
}

ResponseHandlerThread::~ResponseHandlerThread()
{
}

void ResponseHandlerThread::setValue(const std::string request_id,
                const std::string name,
                const std::string content_type,
                unsigned long long content_length,
                const void *data)
{
    m_requestID = (unsigned int)atoi(request_id.c_str());
    m_name = name;
    m_contentType = content_type;
    m_contentLength = content_length;

    m_data = (void*)malloc(sizeof(char)*content_length);
    memcpy(m_data, data, content_length);
}

void ResponseHandlerThread::run()
{
    Client *client = ClientWaitPool::getInstance()->getWaitClient(m_requestID);
    if(client != NULL)
    {
        client->responseReceived(m_name, m_contentType, m_contentLength, m_data);
    }
}
